package com.zd.zjfx.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Date;

public class FileReadUtil {
	static int count=0;
	public static String readFiles(String basepath) throws IOException {
		File file = new File(basepath);
		String[] test = file.list();
		for (int i = 0; i < test.length; i++) {
			//System.out.println(test[i]);
			if (test[i].toLowerCase().endsWith("交易明细信息.csv")) {
				String filepath=basepath+test[i];
				System.out.println(filepath);
				count++;
				//readGABCSVFile(filepath);
				
	        }else if(test[i].toLowerCase().endsWith("人员信息.csv")){
	        	String filepath=basepath+test[i];
	        	System.out.println(filepath);
	        	count++;
	        	//readGABCSVFile(filepath);
	        	
	        }else if(test[i].toLowerCase().endsWith("账户信息.csv")){
	        	String filepath=basepath+test[i];
	        	System.out.println(filepath);
	        	count++;
	        	//readGABCSVFile(filepath);
	        	
	        }else if(test[i].toLowerCase().endsWith("联系方式信息.csv")){
	        	String filepath=basepath+test[i];
	        	System.out.println(filepath);
	        	count++;
	        	readGABCSVFile(filepath);
	        	
	        }else if(test[i].toLowerCase().endsWith("住址信息.csv")){
	        	String filepath=basepath+test[i];
	        	System.out.println(filepath);
	        	count++;
	        	//readGABCSVFile(filepath); 
	        	
	        }else if(test[i].toLowerCase().endsWith("任务信息(成功).csv")){
	        	String filepath=basepath+test[i];
	        	System.out.println(filepath);
	        	count++;
	        	readGABCSVFile(filepath);
	        	
	        }else if(test[i].toLowerCase().endsWith("任务信息(失败).csv")){
	        	String filepath=basepath+test[i];
	        	System.out.println(filepath);
	        	count++;
	        	readGABCSVFile(filepath);
	        	
	        }else{
	        	String filepath=basepath+test[i];
	        	
	        	File f=new File(filepath);
	        	System.out.println(filepath);
	        	if(f.isDirectory()) {
	        		readFiles(filepath+"\\");
	        	}
	        	
	        }
			
		}
		return basepath;
	}

	public static void main(String[] args) throws IOException {
		/**
		 * 解压文件
		 */
		Date a=new Date();
		String f = "F:\\132新\\";
		readFiles(f);
		System.out.println(count);
		Date b=new Date();
		System.out.println(a);
		System.out.println(b);
	}
	/**
	 * 读取公安部csv文件
	 * @param filename  文件地址
	 * @return  返回按行拆分后的数据
	 */
	public static ArrayList<String []> readGABCSVFile(String filename){
		ArrayList<String []> data=new ArrayList<String[]>();
		try {
			InputStreamReader isr=new InputStreamReader(new FileInputStream(filename),"GBK");
			//FileReader fr = new FileReader(filename);
			BufferedReader bf = new BufferedReader(isr);
			String str;
			//先把标题行去掉
			bf.readLine();
			//按行读取字符串
			while ((str = bf.readLine()) != null) {
				System.out.println(str);
				data.add(str.split("	\",\""));
			}
			bf.close();
			isr.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		System.out.println(data.size());
		return data;
		
	}
}
